
(function(){

  var nsWrapper = Basis.DOM.Wrapper;
  var nsLayout = Basis.Layout;

  //
  // Link components
  //
  Basis.Event.onLoad(function(){

    // Layout
    new nsLayout.VerticalPanelStack({
      id: 'AppLayout',
      container: document.body,
      childNodes: [
        {
          childNodes: [
            App.Component.Menu
          ]
        },
        {
          flex: 1,
          childNodes: [
            new nsWrapper.TmplContainer({
              id: 'AppLayoutWrapper',
              childNodes: [
                App.Component.ProjectTree,
                App.Component.TechListViewer
              ]
            })
          ]
        },
        {
          id: 'ConsolePanel',
          childNodes: [
            App.Component.Console
          ]
        }
      ]
    })

    // TODO: убрать эти костыли
    var consolePanel = App.Component.Console.parentNode.element;
    var consoleSplitterClick = true;
    var consoleSplitter = new App.Ext.Splitter({
      element: App.Component.Console.parentNode.element,
      property: 'height',
      handler: {
        move: function(){
          consoleSplitterClick = false;
        },
        over: function(){
          setTimeout(function(){
            consoleSplitterClick = true;
          }, 0);
        }
      }
    });
    Basis.Event.addHandler(consoleSplitter.resizer, 'click', function(){
      App.Component.Console.focus();
      if (!consoleSplitterClick)
        return;

      if (document.getElementById('ConsoleLog').offsetHeight > 1)
        consolePanel.style.height = '0%';
      else
        consolePanel.style.height = '40%';
    });

    consolePanel.style.minHeight = (App.Component.Console.element.offsetHeight - 1) + 'px';
  });

})();